package cn.mandifal.cart.controller;

import cn.mandifal.pojo.DpUser;
import cn.mandifal.user.service.UserService;
import com.alibaba.dubbo.config.annotation.Reference;
import entity.Result;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 用户登陆注册控制层
 * @author shun
 */
@RestController
@RequestMapping("/userLoginController")
public class UserLoginController {
    @Reference(timeout = 3000)
    private UserService userService;
    /**
     * 显示用户名,如果有昵称则显示昵称
     * @return
     */
    @RequestMapping("/showName")
    public Map showName(){
        String name = SecurityContextHolder.getContext().getAuthentication().getName();
        System.out.println(name);
        Map map=new HashMap();
        DpUser oneUser = userService.findOneUser(name);
        if (oneUser != null){
            if (null==oneUser.getNickName()){
                map.put("loginName", name);
            }else{
                map.put("loginName",oneUser.getNickName());
            }
            if (null !=oneUser.getHeadPic()){
                //返回用户头像
                map.put("headPic",oneUser.getHeadPic());
            }
        }else {
            map.put("loginName", name);
        }
        return map;
    }
}
